/**
 * Created by Administrator on 2017/2/13.
 */
var cinemaDao = require('../dao/CinameDao');


module.exports = {
    /**
     * 影吧菜单--影吧信息查询->反馈前台组装
     *      预定每次加载5条
     * @param req
     * @param res
     * http -- post -- ajax : framework --> my-app.js 滚动事件触发 加载
     * rout:cinema
     */
    getCinemaInfoLimitModel: function (req, callback) {
        var resultData = {};

        if (/^\d+$/.test(req.body.lastIndex)) {
            var citycode ;
            var cinema_name;
            var mid;
            if(req.body.mid){
                mid=req.body.mid;
            }
            if(req.body.citycode){
                citycode = req.body.citycode;
            }else{
                citycode = 0;
            }
            if(req.body.cinema_name){
                cinema_name =req.body.cinema_name;
            }else{
                cinema_name =''
            }
            var lastIndex = 0;
            if(/^\d+$/.test(req.body.lastIndex)){
                lastIndex = parseInt(req.body.lastIndex)
            }
            cinemaDao.getCinema({
                citycode: citycode,
                cinema_name: cinema_name,
                mid:mid,
                lat: req.body.lat,
                long: req.body.long,
                lastIndex :lastIndex
            }, function (data) {
                var cinemaInfo = [];
                if (data.isSuccess) {
                    data.rows.forEach(function (val) {
                        cinemaInfo.push({
                            cinema_code: val.cinema_code,
                            cinemaName: val.cinema_name,
                            cinemaAddress: val.cinema_site,
                            cinema_picture: val.cinema_picture,
                            distance: val.distance+'',
                            score: val.score
                        });

                    });
                    callback({
                        message: 'success',
                        status: 'success',
                        data: cinemaInfo
                    });
                } else {
                    callback({
                        message: 'error',
                        status: 'error',
                        data: ''
                    });
                }
            })
        }else{
            callback({
                message: 'error',
                status: 'error',
                data: ''
            });
        }
    }
}



